package com.wegis.demo.service.impl;

import com.wegis.demo.entity.Person;
import com.wegis.demo.mapper.PersonMapper;
import com.wegis.demo.service.IPersonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author slc
 * @since 2021-07-24
 */
@Service
public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person> implements IPersonService {

    @Override
    public Map<String, Object> getPersons() {
        Map<String, Object> mapResult = new HashMap<>();
        List<Person> data = list();
        mapResult.put("data", data);
        return mapResult;
    }

    @Override
    public Map<String, Object> getPersonById(Integer id) {
        Map<String, Object> mapResult = new HashMap<>();
        Person data = getById(id);
        mapResult.put("data", data);
        return mapResult;
    }

//    @Override
//    public Map<String, Object> getPersonByName(String name) {
//        Map<String, Object> mapResult = new HashMap<>();
//        List<Person> data = personMapper.selectList();
//        mapResult.put("data", data);
//        return mapResult;
//    }
//
    @Override
    public Map<String, Object> addPerson(Person person) {
        Map<String, Object> mapResult = new HashMap<>();
        boolean result = save(person);
        if (result) {
            mapResult.put("msg", "添加person成功");
            mapResult.put("status", 200);
            return mapResult;
        }
        mapResult.put("msg", "添加person失败");
        mapResult.put("status", 201);
        return mapResult;
    }

    @Override
    public Map<String, Object> deletePersonById(Integer id) {
        Map<String, Object> mapResult = new HashMap<>();
        boolean result = removeById(id);
        if (result) {
            mapResult.put("msg", "删除person成功");
            mapResult.put("status", 200);
            return mapResult;
        }
        mapResult.put("msg", "删除person失败");
        mapResult.put("status", 201);
        return mapResult;
    }
}
